package com.heima.wemedia.service.service.impl;


import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.entity.WmChannel;
import com.heima.wemedia.service.service.WmChannelService;
import com.heima.wemedia.service.dao.WmChannelDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 自媒体频道表(WmChannel)表服务实现类
 *
 * @author makejava
 * @since 2022-04-12 18:15:06
 */
@Service("wmChannelService")
public class WmChannelServiceImpl implements WmChannelService {
    @Resource
    private WmChannelDao wmChannelDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public WmChannel queryById(Long id) {
        return this.wmChannelDao.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param wmChannel 实例对象
     * @return 实例对象
     */
    @Override
    public WmChannel insert(WmChannel wmChannel) {
        this.wmChannelDao.insert(wmChannel);
        return wmChannel;
    }

    /**
     * 修改数据
     *
     * @param wmChannel 实例对象
     * @return 实例对象
     */
    @Override
    public WmChannel update(WmChannel wmChannel) {
        this.wmChannelDao.update(wmChannel);
        return this.queryById(wmChannel.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.wmChannelDao.deleteById(id) > 0;
    }

    @Override
    public ResponseResult  queryAll() {
        List<WmChannel> channelList = wmChannelDao.queryAll();
        return ResponseResult.okResult(channelList);
    }
}
